import { ResPage } from "@/api/interface";
import { CircleFriend } from "@/api/interface/circleFriend";
import { CircleFriendState } from "@/redux/interface/circleFriend";
import * as types from "@/redux/mutation-types";
import produce from "immer";

export type CircleFriendAction =
	| {
			type: "SET_CIRCLEFRIEND_LIST";
			payload: ResPage<CircleFriend>;
	  }
	| {
			type: "SET_CIRCLEFRIEND_DETAIL";
			payload: CircleFriend;
	  };

const initState: CircleFriendState = {
	circleFriendList: [],
	circleFriendTotal: 0,
	circleFriendDetail: {
		id: 0,
		user_id: 0,
		content: "",
		top: 0,
		createdAt: "",
		updatedAt: "",
		user: {} as any,
		dianzanCount: 0,
		images: [],
		videos: []
	}
};

export default function circleFriend(state: CircleFriendState = initState, action: CircleFriendAction) {
	return produce(state, draftState => {
		switch (action.type) {
			case types.SET_CIRCLEFRIEND_LIST:
				draftState.circleFriendList = action.payload.rows;
				draftState.circleFriendTotal = action.payload.total;
				break;
			case types.SET_CIRCLEFRIEND_DETAIL:
				draftState.circleFriendDetail = action.payload;
				break;
			default:
				break;
		}
	});
}
